<template>
  <div class="app-container">
    <!--    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="入库危险废物来源" prop="zcktzRkly">
            <el-input
              v-model="queryParams.zcktzRkly"
              placeholder="请输入入库危险废物来源"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="危险废物名称" prop="zcktzRkName">
            <el-input
              v-model="queryParams.zcktzRkName"
              placeholder="请输入危险废物名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="种类" prop="zcktzRkZl">
            <el-input
              v-model="queryParams.zcktzRkZl"
              placeholder="请输入种类"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="危险特性" prop="zcktzRkTx">
            <el-input
              v-model="queryParams.zcktzRkTx"
              placeholder="请输入危险特性"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="危险类别" prop="zcktzRkLb">
            <el-input
              v-model="queryParams.zcktzRkLb"
              placeholder="请输入危险类别"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="数量" prop="zcktzRkNum">
            <el-input
              v-model="queryParams.zcktzRkNum"
              placeholder="请输入数量"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="暂存库号" prop="zcktzZckCode">
            <el-input
              v-model="queryParams.zcktzZckCode"
              placeholder="请输入暂存库号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="送交人" prop="zcktzRkSj">
            <el-input
              v-model="queryParams.zcktzRkSj"
              placeholder="请输入送交人"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="接收人" prop="zcktzRkJc">
            <el-input
              v-model="queryParams.zcktzRkJc"
              placeholder="请输入接收人"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="入库日期" prop="zcktzRkTime">
            <el-input
              v-model="queryParams.zcktzRkTime"
              placeholder="请输入入库日期"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="出库危险废物流向" prop="zcktzCkLx">
            <el-input
              v-model="queryParams.zcktzCkLx"
              placeholder="请输入出库危险废物流向"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="危险废物名称" prop="zcktzCkName">
            <el-input
              v-model="queryParams.zcktzCkName"
              placeholder="请输入危险废物名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="种类" prop="zcktzCkZl">
            <el-input
              v-model="queryParams.zcktzCkZl"
              placeholder="请输入种类"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="危险特性" prop="zcktzCkTx">
            <el-input
              v-model="queryParams.zcktzCkTx"
              placeholder="请输入危险特性"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="危险类别" prop="zcktzCkLb">
            <el-input
              v-model="queryParams.zcktzCkLb"
              placeholder="请输入危险类别"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="数量" prop="zcktzCkNum">
            <el-input
              v-model="queryParams.zcktzCkNum"
              placeholder="请输入数量"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="送交人" prop="zcktzCkSj">
            <el-input
              v-model="queryParams.zcktzCkSj"
              placeholder="请输入送交人"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="接收人" prop="zcktzCkJc">
            <el-input
              v-model="queryParams.zcktzCkJc"
              placeholder="请输入接收人"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="出库日期" prop="zcktzCkTime">
            <el-input
              v-model="queryParams.zcktzCkTime"
              placeholder="请输入出库日期"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>-->

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="small"
          @click="handleAdd"
          v-hasPermi="['solidProdution:zcktzInfo:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="small"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['solidProdution:zcktzInfo:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="small"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['solidProdution:zcktzInfo:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="small"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['solidProdution:zcktzInfo:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="zcktzInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <!--      <el-table-column label="暂存库台账ID" align="center" prop="zcktzId" />-->
      <el-table-column label="入库危险废物来源" align="center" prop="zcktzRkly"/>
      <el-table-column label="危险废物名称" align="center" prop="zcktzRkName"/>
      <el-table-column :formatter="typeFormat_r"  label="种类" align="center" prop="zcktzRkZl"/>
      <el-table-column :formatter="typeFormat_tx_r"  label="危险特性" align="center" prop="zcktzRkTx"/>
      <!--      <el-table-column label="危险类别" align="center" prop="zcktzRkLb" />
            <el-table-column label="数量" align="center" prop="zcktzRkNum" />-->
      <el-table-column label="暂存库号" align="center" prop="zcktzZckCode"/>
      <!--      <el-table-column label="送交人" align="center" prop="zcktzRkSj" />
            <el-table-column label="接收人" align="center" prop="zcktzRkJc" />
            <el-table-column label="入库日期" align="center" prop="zcktzRkTime" />-->
      <el-table-column label="出库危险废物流向" align="center" prop="zcktzCkLx"/>
      <el-table-column label="危险废物名称" align="center" prop="zcktzCkName"/>
      <el-table-column :formatter="typeFormat_lb_c" label="种类" align="center" prop="zcktzCkZl"/>
      <!--      <el-table-column label="危险特性" align="center" prop="zcktzCkTx" />
            <el-table-column label="危险类别" align="center" prop="zcktzCkLb" />-->
      <!--      <el-table-column label="数量" align="center" prop="zcktzCkNum" />
            <el-table-column label="送交人" align="center" prop="zcktzCkSj" />
            <el-table-column label="接收人" align="center" prop="zcktzCkJc" />-->
      <el-table-column label="出库日期" align="center" prop="zcktzCkTime"/>
      <!--      <el-table-column label="备注" align="center" prop="remark" />
            <el-table-column label="冗余字段" align="center" prop="other" />
            <el-table-column label="冗余字段" align="center" prop="otherOne" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="small"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['solidProdution:zcktzInfo:edit']"
          >修改
          </el-button>
          <el-button
            size="small"
            @click="handleDelete(scope.row)"
            v-hasPermi="['solidProdution:zcktzInfo:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改暂存库台账对话框 -->
    <el-dialog :title="title" :visible.sync="open" append-to-body width="60%">
      <el-form ref="form" :model="form" :rules="rules" class="clearfix " label-width="140px">
        <div class="content-left" style="margin-left: 10%">
          <div class="title2"><span> </span>入库信息</div>
          <el-form-item label="入库危险废物来源" prop="zcktzRkly">
            <el-input v-model="form.zcktzRkly" placeholder="请输入入库危险废物来源"/>
          </el-form-item>
          <el-form-item label="危险废物名称" prop="zcktzRkName">
            <el-input v-model="form.zcktzRkName" placeholder="请输入危险废物名称"/>
          </el-form-item>
          <el-form-item label="种类" prop="zcktzRkZl">
            <el-select v-model="form.zcktzRkZl" placeholder="请选择">
              <el-option
                v-for="dict in typeOptions_r"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="危险特性" prop="zcktzRkTx">
            <el-select v-model="form.zcktzRkTx" placeholder="请选择">
              <el-option
                v-for="dict in typeOptions_tx_r"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="类别" prop="zcktzRkLb">
            <el-select v-model="form.zcktzRkLb" placeholder="请选择">
              <el-option
                v-for="dict in typeOptions_lb_r"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="数量" prop="zcktzRkNum" type="number">
            <el-input v-model="form.zcktzRkNum" placeholder="请输入数量"/>
          </el-form-item>
          <el-form-item label="暂存库号" prop="zcktzZckCode">
            <el-input v-model="form.zcktzZckCode" placeholder="请输入暂存库号"/>
          </el-form-item>
          <el-form-item label="出库人" prop="zcktzRkSj">
            <el-input v-model="form.zcktzRkSj" placeholder="请输入出库人"/>
          </el-form-item>
          <el-form-item label="接收人" prop="zcktzRkJc">
            <el-input v-model="form.zcktzRkJc" placeholder="请输入接收人"/>
          </el-form-item>
          <el-form-item label="入库日期" prop="zcktzRkTime">
            <el-date-picker v-model="form.zcktzRkTime" clearable
                            placeholder="选择入库日期"
                            size="small"
                            style="width:100%"
                            type="date"
                            value-format="yyyy-MM-dd">
            </el-date-picker>
          </el-form-item>
        </div>
        <div class="content-middle" style="margin-left: 15%">
          <div class="title2"><span> </span>出库信息</div>
          <el-form-item label="出库危险废物流向" prop="zcktzCkLx">
            <el-input v-model="form.zcktzCkLx" placeholder="请输入出库危险废物流向"/>
          </el-form-item>
          <el-form-item label="危险废物名称" prop="zcktzCkName">
            <el-input v-model="form.zcktzCkName" placeholder="请输入危险废物名称"/>
          </el-form-item>
          <el-form-item label="种类" prop="zcktzCkZl">
            <el-select v-model="form.zcktzCkZl" placeholder="请选择">
              <el-option
                v-for="dict in typeOptions_c"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="危险特性" prop="zcktzCkTx">
            <el-select v-model="form.zcktzCkTx" placeholder="请选择">
              <el-option
                v-for="dict in typeOptions_tx_c"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="危险类别" prop="zcktzCkLb">
            <el-select v-model="form.zcktzCkLb" placeholder="请选择">
              <el-option
                v-for="dict in typeOptions_lb_c"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="数量" prop="zcktzCkNum" type="number">
            <el-input v-model="form.zcktzCkNum" placeholder="请输入数量"/>
          </el-form-item>
          <el-form-item label="送交人" prop="zcktzCkSj">
            <el-input v-model="form.zcktzCkSj" placeholder="请输入送交人"/>
          </el-form-item>
          <el-form-item label="接收人" prop="zcktzCkJc">
            <el-input v-model="form.zcktzCkJc" placeholder="请输入接收人"/>
          </el-form-item>
          <el-form-item label="出库日期" prop="zcktzCkTime">
            <el-date-picker v-model="form.zcktzCkTime" clearable
                            placeholder="选择出库日期"
                            size="small"
                            style="width:100%"
                            type="date"
                            value-format="yyyy-MM-dd">
            </el-date-picker>
          </el-form-item>
        </div>
        <!--        <el-form-item label="删除标志" prop="delFlag">
                  <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
                </el-form-item>
                <el-form-item label="备注" prop="remark">
                  <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
                </el-form-item>
                <el-form-item label="冗余字段" prop="other">
                  <el-input v-model="form.other" type="textarea" placeholder="请输入内容" />
                </el-form-item>
                <el-form-item label="冗余字段" prop="otherOne">
                  <el-input v-model="form.otherOne" type="textarea" placeholder="请输入内容" />
                </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer tianjie_button" style="text-align: center; margin-top:30px">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  addZcktzInfo,
  delZcktzInfo,
  exportZcktzInfo,
  getZcktzInfo,
  listZcktzInfo,
  updateZcktzInfo
} from "@/api/solidProdution/zcktzInfo";
import {validatetoTwoPoint,validatePhoneTwo,validateIdNo,validateEMail} from "@/api/validate/validate";

export default {
  name: "ZcktzInfo",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 暂存库台账表格数据
      zcktzInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        zcktzRkly: null,
        zcktzRkName: null,
        zcktzRkZl: null,
        zcktzRkTx: null,
        zcktzRkLb: null,
        zcktzRkNum: null,
        zcktzZckCode: null,
        zcktzRkSj: null,
        zcktzRkJc: null,
        zcktzRkTime: null,
        zcktzCkLx: null,
        zcktzCkName: null,
        zcktzCkZl: null,
        zcktzCkTx: null,
        zcktzCkLb: null,
        zcktzCkNum: null,
        zcktzCkSj: null,
        zcktzCkJc: null,
        zcktzCkTime: null,
        other: null,
        otherOne: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        zcktzRkName: [
          {required: true, message: "入库名称不能为空", trigger: "blur"}
        ],
        zcktzCkName: [
          {required: true, message: "出库名称不能为空", trigger: "blur"}
        ],
      },
      typeOptions_r:[],
      typeOptions_tx_r:[],
      typeOptions_lb_r:[],
      typeOptions_c:[],
      typeOptions_tx_c:[],
      typeOptions_lb_c:[],
    };
  },
  created() {
    this.getDicts("wxfwxt").then(response => {
      this.typeOptions_c = response.data;
      this.typeOptions_r = response.data;
    });
    this.getDicts("wxtx").then(response => {
      this.typeOptions_tx_r = response.data;
      this.typeOptions_tx_c = response.data;
    });
    this.getDicts("wxfwlb").then(response => {
      this.typeOptions_lb_r = response.data;
      this.typeOptions_lb_c = response.data;
    });
    this.getList();
  },
  methods: {
    typeFormat_r(row, column) {
      return this.selectDictLabel(this.typeOptions, row.wxfwczZl);
    },
    typeFormat_tx_r(row, column) {
      return this.selectDictLabel(this.typeOptions_tx, row.wxfwczTx);
    },
    typeFormat_lb_r(row, column) {
      return this.selectDictLabel(this.typeOptions_lb, row.wxfwczLb);
    },

    typeFormat_c(row, column) {
      return this.selectDictLabel(this.typeOptions, row.wxfwczZl);
    },
    typeFormat_tx_c(row, column) {
      return this.selectDictLabel(this.typeOptions_tx, row.wxfwczTx);
    },
    typeFormat_lb_c(row, column) {
      return this.selectDictLabel(this.typeOptions_lb, row.wxfwczLb);
    },
    /** 查询暂存库台账列表 */
    getList() {
      this.loading = true;
      listZcktzInfo(this.queryParams).then(response => {
        this.zcktzInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        zcktzId: null,
        zcktzRkly: null,
        zcktzRkName: null,
        zcktzRkZl: null,
        zcktzRkTx: null,
        zcktzRkLb: null,
        zcktzRkNum: null,
        zcktzZckCode: null,
        zcktzRkSj: null,
        zcktzRkJc: null,
        zcktzRkTime: null,
        zcktzCkLx: null,
        zcktzCkName: null,
        zcktzCkZl: null,
        zcktzCkTx: null,
        zcktzCkLb: null,
        zcktzCkNum: null,
        zcktzCkSj: null,
        zcktzCkJc: null,
        zcktzCkTime: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        other: null,
        otherOne: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.zcktzId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加暂存库台账";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const zcktzId = row.zcktzId || this.ids
      getZcktzInfo(zcktzId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改暂存库台账";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.zcktzId != null) {
            updateZcktzInfo(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addZcktzInfo(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const zcktzIds = row.zcktzId || this.ids;
      this.$confirm('是否确认删除暂存库台账编号为"' + zcktzIds + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delZcktzInfo(zcktzIds);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有暂存库台账数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.exportLoading = true;
        return exportZcktzInfo(queryParams);
      }).then(response => {
        this.download(response.msg);
        this.exportLoading = false;
      }).catch(() => {
      });
    }
  }
};
</script>
